﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;
using System.Data.OleDb;

public partial class delete_room : System.Web.UI.Page
{
    OleDbConnection conx;

    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void Button_Delete_Click(object sender, EventArgs e)
    {
        try
        {
            String con = "Provider=MSDAORA;Data Source=orcl;Password=oracle;User ID=pearl";//"DSN=orcl;Driver={Microsoft ODBC for Oracle};UID=system;PWD=password;SERVER=localhost;";
            conx = new OleDbConnection(con);
            conx.Open();



            if (conx.State == ConnectionState.Open)
            {
                string pk = "";
                foreach (GridViewRow row in GridView1.Rows)
                {
                    CheckBox cbd = (CheckBox)row.FindControl("check_box_delete");
                    if (cbd != null && cbd.Checked)
                    {
                        pk = GridView1.Rows[row.RowIndex].Cells[1].Text;

                        /*Test Delete*/
                        OleDbCommand ODC = new OleDbCommand("DELETE FROM ROOMS WHERE ROOM_NO = '" + pk + "'", conx);
                        ODC.ExecuteNonQuery();
                    }
                }
                GridView1.DataBind();
                Label1.Text = "Rooms have been deleted already!";
            }
            else
                Label1.Text = "Oracle Connect Failed";
        }

        catch (Exception ex)
        {
            Label1.Text = ex.Message + "<br />" + ex.StackTrace;
        }

        finally
        {
            conx.Close();
            conx = null;
        }
    }
    protected void Button_Cancel_Click(object sender, EventArgs e)
    {

    }
    protected void Back_Click(object sender, EventArgs e)
    {
        Response.Redirect("room.aspx");
    }
}